package com.lhm.video.work;

import java.util.List;
import java.util.concurrent.TimeUnit;

import com.jfinal.kit.StrKit;
import com.jfinal.log.Log;
import com.lhm.video.util.ConvertVideo;

public class VideoThread extends Thread {

	private final Log log = Log.getLog(getClass());

	@Override
	public void run() {
		while (true) {
			try {
				List<String> fileNames = ConvertVideo.listNeedConvertVideoFileNames();
				if (ConvertVideo.flag) {
					ConvertVideo.flag = false;
					for (String file : fileNames) {
						if (StrKit.notBlank(file)) {
							log.info(file);
							ConvertVideo.process(file);
						}
					}
					ConvertVideo.flag = true;
				}
			} catch (Exception e) {
				log.error("程序错误" + e.getMessage());
				// TODO: handle exception
			}
			// 30秒后执行
			try {
				TimeUnit.SECONDS.sleep(30);
			} catch (Exception e) {
				log.error("WorkerThread===" + e.getMessage());
				continue;
			}
		}
	}
}
